package test.myorm.chain.demo;

import test.myorm.chain.Chain;
import test.myorm.chain.Interceptor;
import test.myorm.chain.Invocation;
import test.myorm.chain.ProxyFactory;

public class CacheInterceptor implements Interceptor {

	@Override
	public Object invoke(Invocation invocation) {
		System.out.println("cacheInterceptor start...");
		Object result = invocation.invoke();
		System.out.println("cacheInterceptor end...");
		return result;
	}
	
	public static void main(String[] args) {
		Chain chain = new Chain();
		chain.addInterceptor(new LogInterceptor());
		chain.addInterceptor(new CacheInterceptor());
		ProxyFactory factory = new ProxyFactory(chain);
		UserService userService = (UserService) factory.getService(new UserService());
		userService.hello();
		
		chain = new Chain();
		chain.addInterceptor(new LogInterceptor());
		factory = new ProxyFactory();
		userService = (UserService) factory.getService(new UserService(), chain);
		userService.hello();
	}

}
